package logic

import (
	"context"
	"math/rand"
	"time"
	"vip-shop/cache"
	"vip-shop/shoprpc/internal/svc"
	"vip-shop/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SenSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSenSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SenSmsLogic {
	return &SenSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SenSmsLogic) SenSms(in *shoprpc.SenSmsRequest) (*shoprpc.SenSmsResponse, error) {
	// todo: add your logic here and delete this line
	i := rand.Intn(9000) + 1000
	//sms, err := pkg.SenSms(in.Account, strconv.Itoa(i))
	//if err != nil {
	//	return nil, fmt.Errorf("短信验证码获取失败")
	//}
	//if sms.Code != 2 {
	//	return nil, fmt.Errorf(sms.Msg)
	//}
	cache.Rdb.Set(cache.Ctx, "sms"+in.Account, i, time.Minute*5)
	return &shoprpc.SenSmsResponse{}, nil
}
